<template>
	<view class="nav">
		<image src="/static/icon/index.png" mode="" @click='goToPage(1)'></image>
		<view class="nav-location">
			<view v-for="(item,index) in locationList" :key="index" class="location-title" :class="locationactive == index ? 'active' :'' "
			 @click='locationChange(index)'>
				{{item.title}}
			</view>
		</view>
		<image src="/static/icon/home.png" mode="" @click='goToPage(2)'></image>
	</view>
</template>

<script>
	export default {
		name: 'custom-nav',
		data() {
			return {
				locationList: [{
					'type': 1,
					'title': '全国'
				}, {
					'type': 2,
					'title': '附近'
				}],
				locationactive: 0
			}
		},
		methods: {
			//切换全国/附近
			locationChange(index) {
				this.locationactive = index;
				this.$emit('getLocationActive', index);
			},
			//页面跳转
			goToPage(type) {
				let url = '';
				url = type == 1 ? '/pages/index/index' : '/pages/mine/mine';
				if(url){
					uni.switchTab({
						url
					})
				}
			},

		},
		mounted() {
			this.$emit('getLocationActive', this.locationactive);
		}
	}
</script>

<style>
	.nav {
		width: 100%;
		height: 100upx;
		position: fixed;
		top: 0px;
		z-index: 9999;
		background-color: #D46813;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.nav image {
		width: 60upx;
		height: 60upx;
		margin: 0 20upx;
	}

	.nav-location {
		width: 240upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.location-title {
		width: 80upx;
		text-align: center;
		color: #E29676;
	}

	.active {
		color: #FFFFFF;
	}
</style>
